﻿CREATE PROCEDURE [steve].[spSteve_InsertContent]
	@ContentId uniqueidentifier,
	@ContentTypeName varchar(50),
	@Path varchar(255),
	@Language varchar(10),
	@SystemName varchar(50),
	@ExternalId varchar(100),
	@SiteUrlId uniqueidentifier,
	@Title nvarchar(200),
	@Teaser nvarchar(4000),
	@ThumbnailContentId uniqueidentifier,
	@PublicationDate datetime2(7),
	@PublisherUrlId uniqueidentifier,
	@Publisher nvarchar(200),
	@Author nvarchar(200),
	@Height int,
	@Width int,
	@MimeType varchar(50),
	@MimeSubtype varchar(50),
	@ContentDataId uniqueidentifier,

	@RevisionDate datetime2(7),
	@RevisionMembershipId uniqueidentifier,
	@RevisionComment nvarchar(400)

AS

	declare @error int
	
	insert into Content (
		ContentId,
		ContentTypeName,
		[Path],
		[Language],
		[LatestRevisionNumber],
		[SystemName],
		[ExternalId],
		SiteUrlId,
		[CreateDate],
		[CreateMembershipId])
	values (
		@ContentId,
		@ContentTypeName,
		@Path,
		@Language,
		1,
		@SystemName,
		@ExternalId,
		@SiteUrlId,
		@RevisionDate,
		@RevisionMembershipId)
	
	select @error = @@error
	if @error <> 0 return @error

	insert into ContentRevision (
		ContentId,
		RevisionNumber,
		Title,
		Teaser,
		ThumbnailContentId,
		PublicationDate,
		PublisherUrlId,
		Publisher,
		Author,
		Height,
		Width,
		MimeType,
		MimeSubtype,
		ContentDataId,
		RevisionComment,
		RevisionDate,
		RevisionMembershipId)
	values (
		@ContentId,
		1,
		@Title,
		@Teaser,
		@ThumbnailContentId,
		@PublicationDate,
		@PublisherUrlId,
		@Publisher,
		@Author,
		@Height,
		@Width,
		@MimeType,
		@MimeSubtype,
		@ContentDataId,
		@RevisionComment,
		@RevisionDate,
		@RevisionMembershipId)

	select @error = @@error
	if @error <> 0 return @error

	SELECT 1 as LatestRevisionNumber

RETURN 0